package com.hnd.springframework.beans.factory.support;

import com.hnd.springframework.beans.BeansException;
import com.hnd.springframework.beans.factory.config.BeanDefinition;

/**
 * AbstractBeanFactory 对于AbstractAutowireCapableBeanFactory 来说 是一个模板，固定了getBean的流程
 *
 * @author hnd德
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("获取bean实例失败", e);
        }
        addSingleton(beanName, bean);
        return bean;
    }
}
